<template>
  <div class="UserAddForm">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="姓名">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="form.phone"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password"></el-input>
      </el-form-item>
      <el-form-item label="用户类型">
        <el-select v-model="form.type" placeholder="请选择活动区域">
          <el-option label="普通用户" value="0"></el-option>
          <el-option label="管理员" value="1"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="用户状态">
        禁用<el-switch v-model="status"></el-switch>正常
      </el-form-item>

      <el-form-item style="dispaly:flex;">
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "UserAddForm",
  data() {
    return {
      form: {
        name: "",
        phone: "",
        password: "",
        type: "",
        status: 1,
      },
      status: true,
    };
  },
  watch: {
    status() {
      this.form.status = this.status ? 1 : 0;
    },
  },
  methods: {
    onSubmit() {
      let _this = this;
      this.$axios({
        url: "/user/addUser",
        method: "post",
        data: _this.form,
      }).then(function (resp) {
        if (resp.data == 1) {
          alert("增加成功");
          location.reload();
        } else {
          alert("增加失败");
        }
      });
    },
  },
};
</script>